<?php 
$countries = $fleet->getCountryList(); 
echo $commander->getListCommandsPanel('sa-a-d', ''); 
?>
<div class="menu_list">
	<table style="clear:both;" id="menulist" class="item_list" cellspacing="0" cellpadding="0" border="0">
        <thead class="fields">
            <tr>
                <th class="first center">&nbsp;&nbsp;Id&nbsp;&nbsp;</th>
                <th><?php echo ucfirst($txt->getWord('choose')); ?></th>
                <th><?php echo ucfirst($txt->getWord('country')); ?></th>
                <th><?php echo ucfirst($txt->getWord('port')); ?></th>
                <th colspan="2"><?php echo ucfirst($txt->getWord('eta')); ?></th>
                <th colspan="2"><?php echo ucfirst($txt->getWord('etd')); ?></th>
                <th><?php echo ucfirst($txt->getWord('archived')); ?></th>
                <th class="last"><?php echo ucfirst($txt->getWord('delete')); ?></th>
            </tr>
        </thead>
        <tbody>
        	<tr class="items">
	            <td class="first center"><img 	title="<?php echo ucfirst($txt->getWord('new')); ?>"
                                                class="icon command" 
                                                src="<?php echo SYSICONS_URL; ?>add_16.gif" 
                                                onclick="if(document.getElementById('new_schitem_port').value != '') { edit_form.submit(); }" /></td>
	            <td><input title="<?php echo ucfirst($txt->getWord('all')); ?>" class="select_all" type="checkbox" name="select_all" value="" /></td>
	            <td>
                    <select class="medium" name="new_schitem_country" >
                        <option value="--"><?php echo ucfirst($txt->getWord('undefined')); ?></option>
                        <?php 
                        if($countries)
                        {
                            foreach($countries as $country)
                            { echo '<option value="'.$country['iso'].'" '.getIsSelectedHTML($_POST['new_schitem_country'], $country['iso']).'>'.$country['printable_name'].'</option>'; }
                        }
                        ?>
                    </select>
                </td>
	            <td><input class="small-m" name="new_schitem_port" type="text" value="" maxlength="100" id="new_schitem_port" /></td>
	            <td>
                	<input id="new_schitem_eta" class="xsmall-s date_pick" size="10" name="new_schitem_eta" type="text" value="<?php echo date("Y-m-d"); ?>" maxlength="10" />
                </td>
                <td>
                    <select name="new_schitem_etah">
                        <?php
                        for($i=0; $i<24; $i++)
                        {
                            $text = $i;
                            
                            if($i < 10)
                            { $text = '0'.$text; }
                            echo '<option value="'.$i.'">'.$text.'</option>';
                        }
                        ?>
                    </select>:
                    <select name="new_schitem_etam">
                        <?php
                        for($i=0; $i<60; $i++)
                        {
                            $text = $i;
                            
                            if($i < 10)
                            { $text = '0'.$text; }
                            echo '<option value="'.$i.'">'.$text.'</option>';
                        }
                        ?>
                    </select>
                </td>
                <td>
                	<input id="new_schitem_etd" class="xsmall-s date_pick" size="10" name="new_schitem_etd" type="text" value="<?php echo date("Y-m-d"); ?>" maxlength="10" />
                </td>
                <td>
                	<select name="new_schitem_etdh">
                        <?php
                        for($i=0; $i<24; $i++)
                        {
                            $text = $i;
                            
                            if($i < 10)
                            { $text = '0'.$text; }
                            echo '<option value="'.$i.'">'.$text.'</option>';
                        }
                        ?>
                    </select>:
                    <select name="new_schitem_etdm">
                        <?php
                        for($i=0; $i<60; $i++)
                        {
                            $text = $i;
                            
                            if($i < 10)
                            { $text = '0'.$text; }
                            echo '<option value="'.$i.'">'.$text.'</option>';
                        }
                        ?>
                    </select>
                </td>
                <td>&nbsp;</td>
	            <td class="last"></td>
	        </tr>
            <?php 
            if($fleet->CurrentShip->getScheduleItems()):
            foreach($fleet->CurrentShip->getScheduleItems() as $schItem)
            {
            ?>
            <tr class="items">
            	<td class="first center"><?php echo $schItem->getId(); ?><input type="hidden" name="schitem_id[]" value="<?php echo $schItem->getId(); ?>" /></td>
                <td><input class="select_list" type="checkbox" name="selected[]" value="<?php echo $schItem->getId(); ?>" /></td>
                <td>
                    <select class="medium" name="schitem_country[]" >
                        <option value="--" <?php echo getIsSelectedHTML($schItem->getCountry(), '--'); ?>><?php echo ucfirst($txt->getWord('undefined')); ?></option>
                        <?php 
                        if($countries)
                        {
                            foreach($countries as $country)
                            { echo '<option value="'.$country['iso'].'" '.getIsSelectedHTML($schItem->getCountry(), $country['iso']).'>'.$country['printable_name'].'</option>'; }
                        }
                        ?>
                    </select>
                </td>
                <td><input class="small-m" name="schitem_port[]" type="text" value="<?php echo $schItem->getPort(); ?>" maxlength="10" /></td>
                <td>
                	<input id="schitem_eta_<?php echo $schItem->getId(); ?>" class="xsmall-s date_pick" size="10" name="schitem_eta[]" type="text" value="<?php echo $schItem->getEtaDate(); ?>" maxlength="10" />
                </td>
                <td>
                    <select name="schitem_etah[]">
                        <?php
                        for($i=0; $i<24; $i++)
                        {
                            $text = $i;
                            
                            if($i < 10)
                            { $text = '0'.$text; }
                            echo '<option value="'.$i.'" '.getIsSelectedHTML($schItem->getEtaHour(), $i).'>'.$text.'</option>';
                        }
                        ?>
                    </select>:
                    <select name="schitem_etam[]">
                        <?php
                        for($i=0; $i<60; $i++)
                        {
                            $text = $i;
                            
                            if($i < 10)
                            { $text = '0'.$text; }
                            echo '<option value="'.$i.'" '.getIsSelectedHTML($schItem->getEtaMinute(), $i).'>'.$text.'</option>';
                        }
                        ?>
                    </select>
                </td>
                <td>
                	<input id="schitem_etd_<?php echo $schItem->getId(); ?>" class="xsmall-s date_pick" size="10" name="schitem_etd[]" type="text" value="<?php echo $schItem->getEtdDate(); ?>" maxlength="10" />
                </td> 
                <td>
                	<select name="schitem_etdh[]">
                        <?php
                        for($i=0; $i<24; $i++)
                        {
                            $text = $i;
                            
                            if($i < 10)
                            { $text = '0'.$text; }
                            echo '<option value="'.$i.'">'.$text.'</option>';
							echo '<option value="'.$i.'" '.getIsSelectedHTML($schItem->getEtdHour(), $i).'>'.$text.'</option>';
                        }
                        ?>
                    </select>:
                    <select name="schitem_etdm[]">
                        <?php
                        for($i=0; $i<60; $i++)
                        {
                            $text = $i;
                            
                            if($i < 10)
                            { $text = '0'.$text; }
                           echo '<option value="'.$i.'" '.getIsSelectedHTML($schItem->getEtdMinute(), $i).'>'.$text.'</option>';
                        }
                        ?>
                    </select>
                </td>
                <td class="center">&nbsp;
                	<?php echo $commander->getArchiveFieldsObject($schItem); ?>
                    <input type="hidden" name="schitem_archived[]" value="<?php echo $schItem->getArchived(); ?>" />&nbsp;
                </td>
                <td class="last">
                <img title="<?php echo ucfirst($txt->getWord('delete').' '.$txt->getWord('ship')); ?>" class="icon command schitem_delete" src="<?php echo SYSICONS_URL; ?>delete_16.gif" onclick="deleteDialog(<?php echo $schItem->getId(); ?>);" />
                </td>
            </tr>
            <?php
            }
            ?>
            <?php endif; ?>
        </tbody>
    </table>
    <input type="hidden" name="schitem_delete" id="schitem_delete_id" value="0" />
</div>
<script type="text/javascript">
jQuery(".date_pick").datepicker(
{
	inline: true, 
	buttonImage: 'calendar.gif',
	dateFormat: 'yy-mm-dd',
	showButtonPanel: true,
	rangeSelect: true
});

function deleteDialog(shipId)
{
	jQuery('#delete_dialog').dialog('open');
	jQuery('#delete_dialog').dialog({
		bgiframe: true,
		resizable: false,
		height:140,
		modal: true,
		overlay: 
		{
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: 
		{
			'<?php echo ucfirst($txt->getWord('no')); ?>': function() 
			{
				jQuery(this).dialog('close');
			},
			'<?php echo ucfirst($txt->getWord('delete').' '.getWord('item')); ?>': function() 
			{
				jQuery('#schitem_delete_id').val(shipId);
				jQuery(this).dialog('close');
				jQuery('#edit_form').submit();
			}
		}
	});
}
</script>
<div id="delete_dialog" title="<?php echo ucfirst($txt->getWord('delete').' '.$txt->getWord('item')); ?>?" style="display:none; text-align:left;">
	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span><?php echo ucfirst($txt->getWord('sure_you_want_to_delete')); ?></p>
</div>